package com.asl.website.banner.domain;

/**
 * @author 482944566@qq.com
 * @version 1.0
 * @date 2025-05-22
 */

import com.asl.common.utils.StringUtils;
import com.asl.website.common.Language;

/**
 * 轮播图响应DTO
 */
public class BannerDTO {
    private Long id;
    private String title;
    private String subtitle;
    private String imageUrl;
    private String buttonText;
    private Boolean showButton;
    private String buttonLink;
    private Integer sortOrder;
    private String language;
    private Long categoryId;

    public BannerDTO(BizBanner banner, String language) {
        this.id = banner.getId();
        this.imageUrl = banner.getImageUrl();
        this.showButton = banner.getShowButton() == 0;
        this.buttonLink = banner.getButtonLink();
        this.sortOrder = banner.getSortOrder();
        this.categoryId=banner.getCategoryId();
        this.language = language;

        switch (Language.fromCode(language)) {
            case EN_US:
                this.title = StringUtils.firstNonBlank(banner.getTitleEn(), banner.getTitleZh());
                this.subtitle = StringUtils.firstNonBlank(banner.getSubtitleEn(), banner.getSubtitleZh());
                this.buttonText = StringUtils.firstNonBlank(banner.getButtonTextEn(), banner.getButtonTextZh());
                break;
            case DE_DE:
                this.title = StringUtils.firstNonBlank(banner.getTitleDe(), banner.getTitleZh());
                this.subtitle = StringUtils.firstNonBlank(banner.getSubtitleDe(), banner.getSubtitleZh());
                this.buttonText = StringUtils.firstNonBlank(banner.getButtonTextDe(), banner.getButtonTextZh());
                break;
            default: // 默认中文
                this.title = banner.getTitleZh();
                this.subtitle = banner.getSubtitleZh();
                this.buttonText = banner.getButtonTextZh();
        }
    }

    public Long getCategoryId() {
        return categoryId;
    }

    // getters
    public Long getId() {
        return id;
    }

    public String getTitle() {
        return title;
    }

    public String getSubtitle() {
        return subtitle;
    }

    public String getImageUrl() {
        return imageUrl;
    }

    public String getButtonText() {
        return buttonText;
    }

    public Boolean getShowButton() {
        return showButton;
    }

    public String getButtonLink() {
        return buttonLink;
    }

    public Integer getSortOrder() {
        return sortOrder;
    }


    public String getLanguage() {
        return language;
    }
    public void setButtonText(String buttonText) {
        this.buttonText = buttonText;
    }

    public void setButtonLink(String buttonLink) {
        this.buttonLink = buttonLink;
    }
}